<template>
	<view>
		<u-swiper :list="list4" indicator indicatorMode="line" circular></u-swiper>
		<u-sticky offset-top="0" customStyle="backgroun-color:#fff">
			
			<u-grid :border="false">
				<u-grid-item v-for="(baseListItem,baseListIndex) in baseListTab" :key="baseListIndex"
					@click="clickTab(baseListIndex)">
					<u-icon :customStyle="{paddingTop:10+'rpx'}" :name="baseListItem.name" color="#999" :size="22">
					</u-icon>
					<text class="grid-text">{{baseListItem.title}}</text>
				</u-grid-item>
			</u-grid>
			<u-gap marginBottom="10rpx"></u-gap>
			<u-search :show-action="true" actionText="搜索" :animation="true"></u-search>
			<u-gap marginBottom="10rpx"></u-gap>
		</u-sticky>
		<u-text :text="local.lat" color="#e50897">
		</u-text>
		<u-text :text="local.longitude" color="#e50897">
		</u-text>
		<u-action-sheet :show="showSex" :actions="actions" title="请选择性别" description="如果选择保密会报错"
			@close="showSex = false" @select="sexSelect">
		</u-action-sheet>
		
		<u-calendar :show="showDate" :mode="'range'" @confirm="confirmDate"></u-calendar>

		<u-overlay :show="showOverLay">
			<view class="form-bottom" style="width: 100%;
		background: #fff;overflow: auto;">
				<u--form labelPosition="left" labelAlign="top">
					<u-form-item label="姓名" borderBottom labelWidth="120"  prop="user.name" borderBottom>
 
						<u-input v-model="user.name"></u-input>
					</u-form-item>
					<u-form-item label="性别" labelWidth="120"  prop="userInfo.sex" borderBottom @click="showSex = true; hideKeyboard()"
						ref="item1">
						<u--input v-model="user.sex" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none">
						</u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="性别" labelWidth="120"  prop="userInfo.sex" borderBottom @click="showSex = true; hideKeyboard()"
						ref="item1">
						<u--input v-model="user.sex" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none">
						</u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="性别" labelWidth="120"  prop="userInfo.sex" borderBottom @click="showSex = true; hideKeyboard()"
						ref="item1">
						<u--input v-model="user.sex" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none">
						</u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="入住酒店时间" labelWidth="120" >
						<view class="" @click="showDate=true">
							{{user.startDate}}-{{user.endDate}}
						</view>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="图片" labelWidth="120" >
						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="2"></u-upload>
					</u-form-item>
					<u-form-item label="图片" labelWidth="100" >
					
					 <u-album :urls="urls2"></u-album>
					</u-form-item>
					
					<u-form-item label="上传身份证" labelWidth="100">
						<u-upload
							:fileList="fileList6"
							@afterRead="afterRead"
							@delete="deletePic"
							name="6"
							multiple
							:maxCount="1"
							width="250"
							height="150"
						>
							<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" 
							mode="widthFix" style="width: 250px;height: 150px;"></image>
						</u-upload>
					</u-form-item>
					<u-form-item label=" ">
						<view class="" style="display: flex;">
							<u-button class="custom-style" @click="showOverLay=false" size="mini" type="info">取消
							</u-button>
							<u-button @click="submit" size="mini" type="primary">确定</u-button>
						</view>

					</u-form-item>
				</u--form>
			</view>



		</u-overlay>

		<!-- <u-list
					@scrolltolower="scrolltolower"
				>
					<u-list-item
						v-for="(item, index) in indexList"
						:key="index"
					>
						<u-cell
							:title="`列表长度-${index + 1}`"
						>
							<u-avatar
								slot="icon"
								shape="square"
								size="35"
								:src="item.url"
								customStyle="margin: -3px 5px -3px 0"
							></u-avatar>
						</u-cell>
					</u-list-item>
				</u-list>
		 -->
		<u-skeleton :loading="loadingData" :animate="true">
			<u-grid :border="false" @click="click">
				<u-grid-item v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">
					<u-icon :customStyle="{paddingTop:40+'rpx'}" :name="baseListItem.name" color="#999" :size="44">
					</u-icon>
					<text class="grid-text">{{baseListItem.title}}</text>
				</u-grid-item>
			</u-grid>
			<!-- <u-empty
			        mode="car"
			        icon="http://cdn.uviewui.com/uview/empty/car.png"
			>
			</u-empty> -->
			
			<u-divider text="分割线" :dashed="true"></u-divider>
			<u-divider  text="靠右"  textColor="#2979ff"
        lineColor="#2979ff" textPosition="center" :hairline="true"></u-divider>
		
		
		<u-cell-group>
		    <u-cell   isLink>
				<view class="" slot="label">
					<view class="">
						<u-text text="这是一个文本"></u-text> <u-text text="2022-04-19"></u-text>
					</view>
				</view>
				<view class="right-label" slot="value">
					<view class="">
						<u-text text="已经完成"></u-text> <u-text text="2022-08-18"></u-text>
					</view>
					<view class="right-button">
						<u-button size="mini">调整</u-button>
					</view>
				</view>
		    </u-cell>
		    <u-cell
		        title="单元格"
		    	isLink
		    >
		    	<text
		    	    slot="value"
		    	    class="u-slot-value"
		    	>99</text>
		    </u-cell>
			<u-cell
			    title="定位"
				isLink
				@click="gotoPage(0)"
			>
				<text
				    slot="value"
				    class="u-slot-value"
				>定位</text>
			</u-cell>
			<u-cell
			    title="消息"
				isLink
				@click="gotoPage(1)"
			>
				<text
				    slot="value"
				    class="u-slot-value"
				>消息</text>
			</u-cell>
			<u-cell
			    title="支付"
				isLink
				@click="gotoPage(2)"
			>
				<text
				    slot="value"
				    class="u-slot-value"
				>支付</text>
			</u-cell>
			<u-cell
			    title="图表"
				isLink
				@click="gotoPage(3)"
			>
				<text
				    slot="value"
				    class="u-slot-value"
				>图表</text>
			</u-cell>
			<u-cell
			    title="下拉刷新"
				isLink
				@click="gotoPage(4)"
			>
				<text
				    slot="value"
				    class="u-slot-value"
				>下拉刷新</text>
			</u-cell>
			<u-cell
			    title="picker绑定值"
				isLink
				@click="gotoPage(5)"
			>
				<text
				    slot="value"
				    class="u-slot-value"
				>picker绑定值</text>
			</u-cell>
		</u-cell-group>
		</u-skeleton>

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import { PostMenu, GetUserInfo } from '@/config/api.js';
	export default {
		data() {
			let s = new Date();
			s = uni.$u.timeFormat(s, 'yyyy-mm-dd');
			let e = new Date();
			e = uni.$u.timeFormat(e, 'yyyy-mm-dd');
			return {
				title: 'Hello',
				showSex: false,
				user: {
					name: "",
					sex: '',
					startDate: s,
					endDate: e
				},
				showDate: false,
				showOverLay: false,
				loadingData: false,
				actions: [{
						name: '男',
					},
					{
						name: '女',
					},
					{
						name: '保密',
					},
				],
				fileList1: [],

				indexList: [],
				fileList6: [],
				urls2: [
					'https://cdn.uviewui.com/uview/album/1.jpg',
					'https://cdn.uviewui.com/uview/album/2.jpg',
					'https://cdn.uviewui.com/uview/album/3.jpg',
					'https://cdn.uviewui.com/uview/album/4.jpg',
					'https://cdn.uviewui.com/uview/album/5.jpg',
					'https://cdn.uviewui.com/uview/album/6.jpg',
					'https://cdn.uviewui.com/uview/album/7.jpg',
					'https://cdn.uviewui.com/uview/album/8.jpg',
					'https://cdn.uviewui.com/uview/album/9.jpg',
					'https://cdn.uviewui.com/uview/album/10.jpg',
				],
				baseList: [{
						name: 'photo',
						title: '图片'
					},
					{
						name: 'lock',
						title: '锁头'
					},
					{
						name: 'star',
						title: '星星'
					},
					{
						name: 'photo',
						title: '图片'
					},
					{
						name: 'lock',
						title: '锁头'
					},
					{
						name: 'star',
						title: '星星'
					},
				],
				baseListTab: [{
						name: 'photo',
						title: '下拉'
					},
					{
						name: 'lock',
						title: '弹窗'
					},
					
				],
				list4: [{
					url: 'https://cdn.uviewui.com/uview/resources/video.mp4',
					title: '昨夜星辰昨夜风，画楼西畔桂堂东',
					poster: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					type: 'video'
				}, {
					url: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					title: '身无彩凤双飞翼，心有灵犀一点通',
					type: 'image'
				}, {
					url: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
					title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
				}],
				local:{
					lat:"",
					longitude:""
				}

			}
		},
		onInit(e){
			//百度的
		},
		
		
		onLoad(e) {
			 
			
		},
		onReady() {
			this.loadingData = true;
			
			setTimeout(() => {
				this.loadingData = false;
				this.loadmore();
				
			})
		},
		onShow(){
			console.log('dddd',this.$store.state.local.lat);
			this.local = this.$store.state.local;
		},
		onHide(){
			
		},
		onUnload(){
			
		},
		onResize(){
			
			
		},
		onPullDownRefresh(){
			this.loadmore();
		},
		onReachBottom(){
			
		},
		onLaunch() {
			
		},
		onTabItemTap(params){
			console.log(params);
		},
		onShareAppMessage(){
			
		},
		onPageScroll(){
			
		},
		onShareTimeline(){
			
		},
		onAddToFavorites(){
			
		},
		methods: {
			gotoPage(type){
				if(type==0){
					uni.navigateTo({
						url:'/pages/location/index'
					})
				}else if(type==1){
					uni.navigateTo({
						url:'/pages/message/index'
					})
				}else if(type==2){
					uni.navigateTo({
						url:'/pages/wxPay/index'
					})
				}else if (type == 3) {
						uni.navigateTo({
							url:'/static/comm/qEChart/index'
						})
				}else if (type == 4) {
						uni.navigateTo({
							url:'/otherPage/listRefresh/index'
						})
				}else if (type == 5) {
						uni.navigateTo({
							url:'/otherPage/pickers/index'
						})
				}
				
			},
			clickTab(index) {
				if (index == 0) {
					this.showDate = true;
				}
				if (index == 1) {
					this.showOverLay = true;
				}
				
			},
			click(name) {
				this.$refs.uToast.success(`点击了第${name}个`)
			},
			scrolltolower() {
				this.loadmore()
			},
			async loadmore() {
				/* for (let i = 0; i < 30; i++) {
					this.indexList.push({
						url: this.urls[uni.$u.random(0, this.urls.length - 1)]
					})
				} */
				
				// 发出post，假设需要带上token
				/* postMenu({ custom: { auth: true }}).then(() => {
					
				}).catch(() =>{
					
				}) */
				await GetUserInfo({ custom: { auth: true }})
				// await等待，注意与async结合使用
				await PostMenu({ custom: { auth: true }})
				
				
			},
			submit() {
				this.showOverLay = false;
			},
			confirmDate(e) {
				console.log(e);
				if (e.length) {
					this.user.startDate = e[0];

					this.user.endDate = e[e.length - 1];
				}
				this.showDate = false;



			},
			sexSelect(e) {
				this.user.sex = e.name;
			},
			hideKeyboard() {

			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {

					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss">
	.custom-style {
		margin-right: 20rpx;
	}
	.album {
	        @include flex;
	        align-items: flex-start;
	
	        &__avatar {
	             background-color: $u-bg-color;
	             padding: 5px;
	             border-radius: 3px;
	         }
	    
	        &__content {
	             margin-left: 10px;
	             flex: 1;
	         }
	    }
		.right-label{
				display: flex;
			    align-items: center;
				.right-button{
					margin-left: 10rpx;
				}
		}
</style>
